from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-02-23 14:02:35.494595
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 23, Feb, 2022
Time: 14:02:41
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.2386
Nobs: 576.000 HQIC: -48.6538
Log likelihood: 6822.96 FPE: 5.68419e-22
AIC: -48.9192 Det(Omega_mle): 4.86847e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.349358 0.068269 5.117 0.000
L1.Burgenland 0.106629 0.041513 2.569 0.010
L1.Kärnten -0.110950 0.021622 -5.131 0.000
L1.Niederösterreich 0.188578 0.086567 2.178 0.029
L1.Oberösterreich 0.130328 0.085597 1.523 0.128
L1.Salzburg 0.255619 0.043943 5.817 0.000
L1.Steiermark 0.036877 0.058017 0.636 0.525
L1.Tirol 0.101230 0.046788 2.164 0.030
L1.Vorarlberg -0.069419 0.041265 -1.682 0.093
L1.Wien 0.018786 0.076075 0.247 0.805
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.052572 0.147208 0.357 0.721
L1.Burgenland -0.038138 0.089515 -0.426 0.670
L1.Kärnten 0.041406 0.046623 0.888 0.374
L1.Niederösterreich -0.204797 0.186665 -1.097 0.273
L1.Oberösterreich 0.461088 0.184574 2.498 0.012
L1.Salzburg 0.282139 0.094755 2.978 0.003
L1.Steiermark 0.113625 0.125102 0.908 0.364
L1.Tirol 0.304659 0.100890 3.020 0.003
L1.Vorarlberg 0.025561 0.088981 0.287 0.774
L1.Wien -0.028705 0.164041 -0.175 0.861
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.198681 0.034865 5.699 0.000
L1.Burgenland 0.088463 0.021201 4.173 0.000
L1.Kärnten -0.007344 0.011042 -0.665 0.506
L1.Niederösterreich 0.239022 0.044209 5.407 0.000
L1.Oberösterreich 0.163372 0.043714 3.737 0.000
L1.Salzburg 0.039277 0.022442 1.750 0.080
L1.Steiermark 0.026576 0.029629 0.897 0.370
L1.Tirol 0.081332 0.023895 3.404 0.001
L1.Vorarlberg 0.053731 0.021074 2.550 0.011
L1.Wien 0.118877 0.038851 3.060 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.119879 0.034803 3.444 0.001
L1.Burgenland 0.043080 0.021163 2.036 0.042
L1.Kärnten -0.013002 0.011023 -1.180 0.238
L1.Niederösterreich 0.168707 0.044132 3.823 0.000
L1.Oberösterreich 0.338007 0.043637 7.746 0.000
L1.Salzburg 0.100407 0.022402 4.482 0.000
L1.Steiermark 0.110713 0.029577 3.743 0.000
L1.Tirol 0.089954 0.023853 3.771 0.000
L1.Vorarlberg 0.060983 0.021037 2.899 0.004
L1.Wien -0.019066 0.038783 -0.492 0.623
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.123679 0.065560 1.886 0.059
L1.Burgenland -0.046269 0.039866 -1.161 0.246
L1.Kärnten -0.045430 0.020764 -2.188 0.029
L1.Niederösterreich 0.135523 0.083132 1.630 0.103
L1.Oberösterreich 0.164483 0.082201 2.001 0.045
L1.Salzburg 0.284269 0.042200 6.736 0.000
L1.Steiermark 0.057867 0.055715 1.039 0.299
L1.Tirol 0.156808 0.044932 3.490 0.000
L1.Vorarlberg 0.097121 0.039628 2.451 0.014
L1.Wien 0.074957 0.073057 1.026 0.305
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.079867 0.051110 1.563 0.118
L1.Burgenland 0.025635 0.031079 0.825 0.409
L1.Kärnten 0.053533 0.016187 3.307 0.001
L1.Niederösterreich 0.188617 0.064809 2.910 0.004
L1.Oberösterreich 0.331446 0.064083 5.172 0.000
L1.Salzburg 0.033992 0.032898 1.033 0.301
L1.Steiermark 0.005615 0.043435 0.129 0.897
L1.Tirol 0.119621 0.035028 3.415 0.001
L1.Vorarlberg 0.066287 0.030894 2.146 0.032
L1.Wien 0.097136 0.056954 1.706 0.088
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169916 0.061781 2.750 0.006
L1.Burgenland 0.004441 0.037568 0.118 0.906
L1.Kärnten -0.065911 0.019567 -3.368 0.001
L1.Niederösterreich -0.107585 0.078341 -1.373 0.170
L1.Oberösterreich 0.209856 0.077463 2.709 0.007
L1.Salzburg 0.053357 0.039767 1.342 0.180
L1.Steiermark 0.248360 0.052504 4.730 0.000
L1.Tirol 0.499195 0.042342 11.790 0.000
L1.Vorarlberg 0.064478 0.037344 1.727 0.084
L1.Wien -0.072903 0.068846 -1.059 0.290
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.159828 0.068513 2.333 0.020
L1.Burgenland -0.003198 0.041661 -0.077 0.939
L1.Kärnten 0.062862 0.021699 2.897 0.004
L1.Niederösterreich 0.165193 0.086876 1.901 0.057
L1.Oberösterreich -0.052635 0.085903 -0.613 0.540
L1.Salzburg 0.207100 0.044100 4.696 0.000
L1.Steiermark 0.139096 0.058224 2.389 0.017
L1.Tirol 0.055391 0.046956 1.180 0.238
L1.Vorarlberg 0.146965 0.041413 3.549 0.000
L1.Wien 0.122430 0.076347 1.604 0.109
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.392357 0.040202 9.760 0.000
L1.Burgenland -0.003706 0.024446 -0.152 0.880
L1.Kärnten -0.021237 0.012733 -1.668 0.095
L1.Niederösterreich 0.200372 0.050978 3.931 0.000
L1.Oberösterreich 0.230934 0.050407 4.581 0.000
L1.Salzburg 0.036853 0.025877 1.424 0.154
L1.Steiermark -0.017003 0.034165 -0.498 0.619
L1.Tirol 0.090268 0.027553 3.276 0.001
L1.Vorarlberg 0.051007 0.024300 2.099 0.036
L1.Wien 0.043063 0.044799 0.961 0.336
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036235 0.100512 0.168471 0.136931 0.094414 0.080549 0.031635 0.208778
Kärnten 0.036235 1.000000 -0.027701 0.132386 0.048270 0.085397 0.443672 -0.067253 0.089199
Niederösterreich 0.100512 -0.027701 1.000000 0.310179 0.118172 0.270068 0.066311 0.151720 0.288282
Oberösterreich 0.168471 0.132386 0.310179 1.000000 0.213557 0.293601 0.167131 0.136139 0.235206
Salzburg 0.136931 0.048270 0.118172 0.213557 1.000000 0.123255 0.090884 0.103972 0.122992
Steiermark 0.094414 0.085397 0.270068 0.293601 0.123255 1.000000 0.134705 0.106369 0.032495
Tirol 0.080549 0.443672 0.066311 0.167131 0.090884 0.134705 1.000000 0.062732 0.151693
Vorarlberg 0.031635 -0.067253 0.151720 0.136139 0.103972 0.106369 0.062732 1.000000 -0.004871
Wien 0.208778 0.089199 0.288282 0.235206 0.122992 0.032495 0.151693 -0.004871 1.000000